package net.mihome.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import net.mihome.app.R;
import net.mihome.app.bean.Community;

import java.util.List;

public class SimpleSpinnerAdapter  extends BaseAdapter {
	    private List<Community> mList;
	    private Context mContext;
	 
	    public SimpleSpinnerAdapter(Context pContext, List<Community> pList) {
	        this.mContext = pContext;
	        this.mList = pList;
	    }
	 
	    @Override
	    public int getCount() {
	        return mList.size();
	    }
	 
	    @Override
	    public Object getItem(int position) {
	        return mList.get(position);
	    }
	 
	    @Override
	    public long getItemId(int position) {
	        return mList.get(position).getId();
	    }
	    /**
	     * 下面是重要代码
	     */
	    @Override
	    public View getView(int position, View convertView, ViewGroup parent) {
		        LayoutInflater _LayoutInflater=LayoutInflater.from(mContext);
		        convertView=_LayoutInflater.inflate(R.layout.spinner_item, null);
		        if(convertView!=null)
		        {
		            TextView item_tTextView=(TextView)convertView.findViewById(R.id.spinner_item_text);
		            item_tTextView.setText(mList.get(position).getName());
		        }
	        return convertView;
	    }
}
